<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .list {
            width: 1226px;
            margin: 0 auto;
            font-size: 12px;
            margin-top: 50px;
        }

        .list .list-item {
            float: left;
            box-sizing: border-box;
            width: 20%;
            padding: 10px;
        }

        .list .list-item img {
            display: block;
            width: 80%;
            margin: 10px auto;
        }

        .list .list-item .title {
            font-size: 14px;
            font-weight: bold;
            line-height: 20px;
        }

        .list .list-item .desc {
            line-height: 20px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .list .list-item:hover {
            box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.5);
        }
    </style>
</head>

<body>
    <div class="list clear">
        <!-- <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div>
        <div class="list-item">
            <a href="">
                <img src="https://img10.360buyimg.com/n7/jfs/t1/123577/14/23921/124639/62ac5867E21551239/c6fbf70114a0a95f.jpg"
                    alt="">
                <div class="title">华为畅享</div>
                <div class="desc">华为畅享 20e 5000mAh大电池6.3英寸高清大屏 4GB+128GB幻夜黑华为 手机标配</div>
                <div class="price">
                    <span class="cur">
                        ¥ 2999.00
                    </span>
                </div>
            </a>
        </div> -->
    </div>
</body>
<script>

    var listDiv = document.getElementsByClassName("list")[0];

    var xhr = new XMLHttpRequest(); // 0 

    xhr.open("get", "../data/list.json", true);  // 1

    xhr.send();

    xhr.onreadystatechange = function () {
        // 2 3 4
        if (xhr.readyState == 4 && xhr.status == 200) {
            var result = xhr.responseText;
            // console.log(result);

            var data = JSON.parse(result);
            console.log(data);

            // 拿到数据之后动态生成 
            var { list } = data;
            console.log(list);

            var html = "";

            list.forEach(function (item) {
                var { title, desc, img, link, oprice, cprice } = item; // 每件商品信息{}
                html += `<div class="list-item">
                    <a href="${link}">
                        <img src="${img}"
                            alt="">
                        <div class="title">${title}</div>
                        <div class="desc">${desc}</div>
                        <div class="price">
                            <span class="cur">
                                ¥${cprice}
                            </span>
                        </div>
                    </a>
                </div>`
            })

            listDiv.innerHTML = html;


        }


    }





</script>

</html>